package com.phoenix.sgs.faq;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.phoenix.sgs.faq.R.string;

import android.app.ListActivity;
import android.content.Intent;
import android.content.res.Resources;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.TextView;
import android.widget.Toast;


public class MainActivity extends ListActivity {
	private List<Map<String, Object>> mData;
	
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setListAdapter(new ArrayAdapter<String>(this, R.layout.main, getCategories()));

        ListView lv = getListView();
        lv.setTextFilterEnabled(true);

        lv.setOnItemClickListener(new OnItemClickListener() {
        	public void onItemClick(
        		AdapterView<?> parent, 
        		View view,
        		int position, 
        		long id) {        		
        		openCategory(((TextView) view).getText().toString());
        	}
        });
    }
    
    private String[] getCategories() {
    	Resources res = getResources();
    	String[] categories = new String[] {
    		res.getString(string.poker_type_base),
    		res.getString(string.poker_type_equipment),
    		res.getString(string.poker_type_ability),
    		res.getString(string.poker_type_general)
    	};
    	
    	return categories;
    }
    
    private void openCategory(String categoryText) {
    	Class<?> clazz = null;
    	Resources res = getResources();
    	if (categoryText == res.getString(string.poker_type_general)) {
    		clazz = CategoryGeneralActivity.class;
    		Intent intent = new Intent(this, clazz);
        	startActivity(intent);
    	} else {
    		Toast.makeText(
                	getApplicationContext(), 
                	categoryText,
                    Toast.LENGTH_SHORT)
                    .show();
    	}
    }
    
    private List<Map<String, Object>> getData() {
    	List<Map<String, Object>> list = new ArrayList<Map<String, Object>>();
    	
    	Map<String, Object> map = new HashMap<String, Object>();
    	map.put("category", "基本牌");
    	list.add(map);
    	
    	map = new HashMap<String, Object>();
    	map.put("category", "装备牌");
    	list.add(map);
    	
    	map = new HashMap<String, Object>();
    	map.put("category", "锦囊牌");
    	list.add(map);
    	
    	map = new HashMap<String, Object>();
    	map.put("category", "武将牌");
    	list.add(map);
    	
    	return list;
    }
}